
Partial Class Admin_LocalProgramOffices
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load
        SetupJavaScript()
        ClearStatus()
        If Not Page.IsPostBack Then
            Me.LocalProgramLabel.Text = EntityController.GetSingleDisplayName("Local Program Office")
            Me.ProgramOfficesScrollingGridView.Sort("LocalProgramName", SortDirection.Ascending)
        End If

    End Sub

    Private Sub SetupJavaScript()

        EntityController.JavaScriptAddChildDiv(Me.ProgramOfficesScrollingGridView.DivClientId, CInt(Me.ProgramOfficesScrollingGridView.ToolTip))
        ClientScript.RegisterStartupScript(Me.GetType(), "scrollDivs", EntityController.JavaScriptScrollingGridStartup(Me.ProgramOfficesScrollingGridView), True)
        EntityController.JavaScriptSetFixedHeight(34)
    End Sub

    Private Sub ClearStatus()
        SetStatus("")
    End Sub
    Private Sub SetStatus(ByVal message As String)
        Dim mymaster As ASP.admin_admin_master = CType(Me.Master, ASP.admin_admin_master)
        mymaster.SetStatus(message)
    End Sub

    Protected Sub AddLocalProgramButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddLocalProgramButton.Click
        Dim localProgram As New Cdm.DataCore.Entities.LocalProgram()
        localProgram.LocalProgramName = Me.NewLocalProgramName.Text
        localProgram.LastModified = UserAuthorization.CurrentUser.LogonId
        localProgram.DateModified = System.DateTime.Now
        localProgram.Persist()
        Me.NewLocalProgramName.Text = ""
        Me.ProgramOfficesScrollingGridView.DataBind()
        SetStatus("New Office Added.")
    End Sub

    Protected Sub ProgramOfficesScrollingGridView_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProgramOfficesScrollingGridView.DataBound
        AccessibilityController.AddImageToSortableGridHeaders(ProgramOfficesScrollingGridView)
    End Sub

    Protected Sub ProgramOfficesScrollingGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles ProgramOfficesScrollingGridView.RowCancelingEdit
        SetStatus("Update Cancelled.")
    End Sub

    Protected Sub ProgramOfficesScrollingGridView_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles ProgramOfficesScrollingGridView.RowUpdated
        SetStatus("Item updated.")
    End Sub

    Protected Sub ProgramOfficesScrollingGridView_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles ProgramOfficesScrollingGridView.RowUpdating

        Dim key As DataKey = Me.ProgramOfficesScrollingGridView.DataKeys(e.RowIndex)
        Dim localProgram As Cdm.DataCore.Entities.LocalProgram
        localProgram = Cdm.DataCore.Entities.LocalProgram.Retrieve(CInt(key.Value.ToString))

        If e.NewValues.Item(0) IsNot Nothing Then
            localProgram.LocalProgramName = e.NewValues.Item(0).ToString
        Else
            localProgram.LocalProgramName = ""
        End If
        localProgram.LastModified = UserAuthorization.CurrentUser.LogonId
        localProgram.DateModified = Now()
        localProgram.Persist()

        e.Cancel = True
        SetStatus("Item updated.")
        Me.ProgramOfficesScrollingGridView.EditIndex = -1
    End Sub
End Class
